#include "CBitmap.h"
#include "../Renderer/Header Files/CAssetManager_AL.h"
#include "../Game Objects/Header Files/CObjectManager.h"
#include "../Renderer/Header Files/CSpriteNode_AL.h"

void CBitmap::PrintTextKerned(string _text, D3DXVECTOR3 _nPos, D3DXVECTOR3 _fScale)
{
	int nOrigX = (int)_nPos.x;
	int len = _text.size();


	for (int i = 0; i < len; ++i)
	{
		char ch = _text[i];
		if (ch == ' ')
		{
			//shift over
			_nPos.x += (int)(32 * _fScale.x);

			continue;
		}
		if (ch == '\n')
		{
			_nPos.y += (int)((m_nCharWidth[0].bottom - m_nCharWidth[0].top) * _fScale.y);
			_nPos.x = (float)nOrigX;

			continue;
		}
		else
		{
			if (i > 0)
				_nPos.x += (int)(m_nWidth* _fScale.x);
		}
		int id = (int)(ch - m_cStartChar);
		CSpriteNode_AL* textNode = new CSpriteNode_AL(CAssetManager_AL::GetInstance()->GetTexture(m_nImageID), m_nCharWidth[id], _nPos, _fScale);
		CBaseObject* bText = new CBaseObject(textNode);
		bText->SetPosition(_nPos);
		CObjectManager::GetInstance()->AddItemToObjects(bText);
		_nPos.x = (_nPos.x + (m_nCharWidth[id].right - m_nCharWidth[id].left)*_fScale.x);
	}
}

//basic draw
void CBitmap::DrawText(string _stuffToPrint, D3DXVECTOR3 _nPos, D3DXVECTOR3 _fScale)
{

	int nOrigX = (int)_nPos.x;
	int len = _stuffToPrint.size();
	bool newLineFlag = false;

	for (int i = 0; i < len; ++i)
	{
		char ch = _stuffToPrint[i];
		if (ch == ' ')
		{
			//shift over
			_nPos.x += (int)(m_nWidth * _fScale.x);

			continue;
		}
		if (ch == '\n')
		{
			_nPos.y += (int)(m_nHeight * _fScale.y);
			_nPos.x = (float)nOrigX;
			newLineFlag = true;
			continue;
		}
		else
		{
			if (i > 0 && !newLineFlag)
				_nPos.x += (m_nWidth* _fScale.x);
		}
		int id = (int)(ch - m_cStartChar);
		RECT srcRect = CellAlgorithm(id);			//	center,rot
		CSpriteNode_AL* textNode = new CSpriteNode_AL(CAssetManager_AL::GetInstance()->GetTexture(m_nImageID), srcRect, _nPos, _fScale);
		CBaseObject* bText = new CBaseObject(textNode);
		CObjectManager::GetInstance()->AddItemToObjects(bText);
	
	}

}

void CBitmap::LoadBasicText()
{
	SetImageID(CAssetManager_AL::GetInstance()->CreateTexture("Fonts\\BitmapFontShaded.png"));
	SetStartChar(33);

	//	!
	m_nCharWidth[0].left = 19;
	m_nCharWidth[0].top = 0;
	m_nCharWidth[0].right = 30;
	m_nCharWidth[0].bottom = 85;
	//	"
	m_nCharWidth[1].left = 30;
	m_nCharWidth[1].top = 0;
	m_nCharWidth[1].right = 50;
	m_nCharWidth[1].bottom = 85;
	//	#
	m_nCharWidth[2].left = 50;
	m_nCharWidth[2].top = 0;
	m_nCharWidth[2].right = 90;
	m_nCharWidth[2].bottom = 85;
	//	$
	m_nCharWidth[3].left = 114;
	m_nCharWidth[3].top = 0;
	m_nCharWidth[3].right = 155;
	m_nCharWidth[3].bottom = 85;
	//	%
	m_nCharWidth[4].left = 156;
	m_nCharWidth[4].top = 0;
	m_nCharWidth[4].right = 198;
	m_nCharWidth[4].bottom = 85;
	//	&
	m_nCharWidth[5].left = 198;
	m_nCharWidth[5].top = 0;
	m_nCharWidth[5].right = 263;
	m_nCharWidth[5].bottom = 85;
	//	'
	m_nCharWidth[6].left = 263;
	m_nCharWidth[6].top = 0;
	m_nCharWidth[6].right = 276;
	m_nCharWidth[6].bottom = 85;
	//	(
	m_nCharWidth[7].left = 276;
	m_nCharWidth[7].top = 0;
	m_nCharWidth[7].right = 303;
	m_nCharWidth[7].bottom = 85;
	//	)
	m_nCharWidth[8].left = 303;
	m_nCharWidth[8].top = 0;
	m_nCharWidth[8].right = 330;
	m_nCharWidth[8].bottom = 85;
	//	*
	m_nCharWidth[9].left = 330;
	m_nCharWidth[9].top = 0;
	m_nCharWidth[9].right = 358;
	m_nCharWidth[9].bottom = 85;
	//	+
	m_nCharWidth[10].left = 358;
	m_nCharWidth[10].top = 0;
	m_nCharWidth[10].right = 400;
	m_nCharWidth[10].bottom = 85;
	//	,
	m_nCharWidth[11].left = 400;
	m_nCharWidth[11].top = 0;
	m_nCharWidth[11].right = 412;
	m_nCharWidth[11].bottom = 85;
	//	-
	m_nCharWidth[12].left = 412;
	m_nCharWidth[12].top = 0;
	m_nCharWidth[12].right = 456;
	m_nCharWidth[12].bottom = 85;
	//	.
	m_nCharWidth[13].left = 456;
	m_nCharWidth[13].top = 0;
	m_nCharWidth[13].right = 469;
	m_nCharWidth[13].bottom = 85;
	//	/
	m_nCharWidth[14].left = 469;
	m_nCharWidth[14].top = 0;
	m_nCharWidth[14].right = 497;
	m_nCharWidth[14].bottom = 85;
	//	0
	m_nCharWidth[15].left = 497;
	m_nCharWidth[15].top = 0;
	m_nCharWidth[15].right = 541;
	m_nCharWidth[15].bottom = 85;
	//	1
	m_nCharWidth[16].left = 541;
	m_nCharWidth[16].top = 0;
	m_nCharWidth[16].right = 566;
	m_nCharWidth[16].bottom = 85;
	//	2
	m_nCharWidth[17].left = 566;
	m_nCharWidth[17].top = 0;
	m_nCharWidth[17].right = 602;
	m_nCharWidth[17].bottom = 85;
	//	3
	m_nCharWidth[18].left = 602;
	m_nCharWidth[18].top = 0;
	m_nCharWidth[18].right = 636;
	m_nCharWidth[18].bottom = 85;
	//	4
	m_nCharWidth[19].left = 636;
	m_nCharWidth[19].top = 0;
	m_nCharWidth[19].right = 672;
	m_nCharWidth[19].bottom = 85;
	//	5
	m_nCharWidth[20].left = 672;
	m_nCharWidth[20].top = 0;
	m_nCharWidth[20].right = 708;
	m_nCharWidth[20].bottom = 85;
	//	6
	m_nCharWidth[21].left = 708;
	m_nCharWidth[21].top = 0;
	m_nCharWidth[21].right = 743;
	m_nCharWidth[21].bottom = 85;
	//	7
	m_nCharWidth[22].left = 743;
	m_nCharWidth[22].top = 0;
	m_nCharWidth[22].right = 778;
	m_nCharWidth[22].bottom = 85;
	//	8
	m_nCharWidth[23].left = 778;
	m_nCharWidth[23].top = 0;
	m_nCharWidth[23].right = 812;
	m_nCharWidth[23].bottom = 85;
	//	9
	m_nCharWidth[24].left = 812;
	m_nCharWidth[24].top = 0;
	m_nCharWidth[24].right = 848;
	m_nCharWidth[24].bottom = 85;
	//	:
	m_nCharWidth[25].left = 848;
	m_nCharWidth[25].top = 10;
	m_nCharWidth[25].right = 860;
	m_nCharWidth[25].bottom = 95;
	//	;
	m_nCharWidth[26].left = 860;
	m_nCharWidth[26].top = 0;
	m_nCharWidth[26].right = 874;
	m_nCharWidth[26].bottom = 85;
	//	<
	m_nCharWidth[27].left = 874;
	m_nCharWidth[27].top = 0;
	m_nCharWidth[27].right = 901;
	m_nCharWidth[27].bottom = 85;
	//	=
	m_nCharWidth[28].left = 901;
	m_nCharWidth[28].top = 0;
	m_nCharWidth[28].right = 943;
	m_nCharWidth[28].bottom = 85;
	//	>
	m_nCharWidth[29].left = 943;
	m_nCharWidth[29].top = 0;
	m_nCharWidth[29].right = 971;
	m_nCharWidth[29].bottom = 85;
	//	?
	m_nCharWidth[30].left = 971;
	m_nCharWidth[30].top = 0;
	m_nCharWidth[30].right = 1007;
	m_nCharWidth[30].bottom = 85;
	//	@
	m_nCharWidth[31].left = 0;
	m_nCharWidth[31].top = 105;
	m_nCharWidth[31].right = 62;
	m_nCharWidth[31].bottom = 177;
	//	A
	m_nCharWidth[32].left = 61;
	m_nCharWidth[32].top = 102;
	m_nCharWidth[32].right = 105;
	m_nCharWidth[32].bottom = 178;
	//	B
	m_nCharWidth[33].left = 104;
	m_nCharWidth[33].top = 105;
	m_nCharWidth[33].right = 146;
	m_nCharWidth[33].bottom = 177;
	//	C
	m_nCharWidth[34].left = 146;
	m_nCharWidth[34].top = 105;
	m_nCharWidth[34].right = 182;
	m_nCharWidth[34].bottom = 177;
	//	D
	m_nCharWidth[35].left = 182;
	m_nCharWidth[35].top = 105;
	m_nCharWidth[35].right = 224;
	m_nCharWidth[35].bottom = 177;
	//	E
	m_nCharWidth[36].left = 224;
	m_nCharWidth[36].top = 105;
	m_nCharWidth[36].right = 267;
	m_nCharWidth[36].bottom = 177;
	//	F
	m_nCharWidth[37].left = 267;
	m_nCharWidth[37].top = 105;
	m_nCharWidth[37].right = 308;
	m_nCharWidth[37].bottom = 177;
	//	G
	m_nCharWidth[38].left = 308;
	m_nCharWidth[38].top = 105;
	m_nCharWidth[38].right = 344;
	m_nCharWidth[38].bottom = 177;
	//	H
	m_nCharWidth[39].left = 344;
	m_nCharWidth[39].top = 105;
	m_nCharWidth[39].right = 387;
	m_nCharWidth[39].bottom = 177;
	//	I
	m_nCharWidth[40].left = 387;
	m_nCharWidth[40].top = 105;
	m_nCharWidth[40].right = 409;
	m_nCharWidth[40].bottom = 177;
	//	J
	m_nCharWidth[41].left = 409;
	m_nCharWidth[41].top = 105;
	m_nCharWidth[41].right = 442;
	m_nCharWidth[41].bottom = 177;
	//	K
	m_nCharWidth[42].left = 442;
	m_nCharWidth[42].top = 105;
	m_nCharWidth[42].right = 484;
	m_nCharWidth[42].bottom = 177;
	//	L
	m_nCharWidth[43].left = 484;
	m_nCharWidth[43].top = 105;
	m_nCharWidth[43].right = 526;
	m_nCharWidth[43].bottom = 177;
	//	M
	m_nCharWidth[44].left = 526;
	m_nCharWidth[44].top = 105;
	m_nCharWidth[44].right = 591;
	m_nCharWidth[44].bottom = 177;
	//	N
	m_nCharWidth[45].left = 591;
	m_nCharWidth[45].top = 105;
	m_nCharWidth[45].right = 642;
	m_nCharWidth[45].bottom = 177;
	//	O
	m_nCharWidth[46].left = 644;
	m_nCharWidth[46].top = 105;
	m_nCharWidth[46].right = 674;
	m_nCharWidth[46].bottom = 177;
	//	P
	m_nCharWidth[47].left = 676;
	m_nCharWidth[47].top = 105;
	m_nCharWidth[47].right = 714;
	m_nCharWidth[47].bottom = 177;
	//	Q
	m_nCharWidth[48].left = 716;
	m_nCharWidth[48].top = 105;
	m_nCharWidth[48].right = 760;
	m_nCharWidth[48].bottom = 177;
	//	R
	m_nCharWidth[49].left = 760;
	m_nCharWidth[49].top = 105;
	m_nCharWidth[49].right = 804;
	m_nCharWidth[49].bottom = 177;
	//	S
	m_nCharWidth[50].left = 804;
	m_nCharWidth[50].top = 105;
	m_nCharWidth[50].right = 838;
	m_nCharWidth[50].bottom = 177;
	//	T
	m_nCharWidth[51].left = 838;
	m_nCharWidth[51].top = 105;
	m_nCharWidth[51].right = 878;
	m_nCharWidth[51].bottom = 177;
	//	U
	m_nCharWidth[52].left = 878;
	m_nCharWidth[52].top = 105;
	m_nCharWidth[52].right = 915;
	m_nCharWidth[52].bottom = 177;
	//	V
	m_nCharWidth[53].left = 916;
	m_nCharWidth[53].top = 105;
	m_nCharWidth[53].right = 950;
	m_nCharWidth[53].bottom = 177;
	//	W
	m_nCharWidth[54].left = 950;
	m_nCharWidth[54].top = 105;
	m_nCharWidth[54].right = 1008;
	m_nCharWidth[54].bottom = 177;
	//	X
	m_nCharWidth[55].left = 1008;
	m_nCharWidth[55].top = 105;
	m_nCharWidth[55].right = 1050;
	m_nCharWidth[55].bottom = 177;
	//	Y
	m_nCharWidth[56].left = 1050;
	m_nCharWidth[56].top = 105;
	m_nCharWidth[56].right = 1092;
	m_nCharWidth[56].bottom = 177;
	//	Z
	m_nCharWidth[57].left = 1092;
	m_nCharWidth[57].top = 105;
	m_nCharWidth[57].right = 1134;
	m_nCharWidth[57].bottom = 177;
	//	[
	m_nCharWidth[58].left = 0;
	m_nCharWidth[58].top = 196;
	m_nCharWidth[58].right = 22;
	m_nCharWidth[58].bottom = 294;
	//	\ 
	m_nCharWidth[59].left = 22;
	m_nCharWidth[59].top = 196;
	m_nCharWidth[59].right = 52;
	m_nCharWidth[59].bottom = 294;
	//	]
	m_nCharWidth[60].left = 52;
	m_nCharWidth[60].top = 196;
	m_nCharWidth[60].right = 80;
	m_nCharWidth[60].bottom = 294;
	//	^
	m_nCharWidth[61].left = 80;
	m_nCharWidth[61].top = 196;
	m_nCharWidth[61].right = 108;
	m_nCharWidth[61].bottom = 294;
	//	_
	m_nCharWidth[62].left = 108;
	m_nCharWidth[62].top = 196;
	m_nCharWidth[62].right = 150;
	m_nCharWidth[62].bottom = 294;
	//	`
	m_nCharWidth[63].left = 150;
	m_nCharWidth[63].top = 196;
	m_nCharWidth[63].right = 172;
	m_nCharWidth[63].bottom = 294;
	//	a
	m_nCharWidth[64].left = 172;
	m_nCharWidth[64].top = 196;
	m_nCharWidth[64].right = 214;
	m_nCharWidth[64].bottom = 294;
	//	b
	m_nCharWidth[65].left = 214;
	m_nCharWidth[65].top = 196;
	m_nCharWidth[65].right = 256;
	m_nCharWidth[65].bottom = 294;
	//	c
	m_nCharWidth[66].left = 256;
	m_nCharWidth[66].top = 196;
	m_nCharWidth[66].right = 290;
	m_nCharWidth[66].bottom = 294;
	//	d
	m_nCharWidth[67].left = 290;
	m_nCharWidth[67].top = 196;
	m_nCharWidth[67].right = 332;
	m_nCharWidth[67].bottom = 294;
	//	e
	m_nCharWidth[68].left = 335;
	m_nCharWidth[68].top = 196;
	m_nCharWidth[68].right = 368;
	m_nCharWidth[68].bottom = 294;
	//	f
	m_nCharWidth[69].left = 368;
	m_nCharWidth[69].top = 196;
	m_nCharWidth[69].right = 412;
	m_nCharWidth[69].bottom = 294;
	//	g
	m_nCharWidth[70].left = 412;
	m_nCharWidth[70].top = 196;
	m_nCharWidth[70].right = 454;
	m_nCharWidth[70].bottom = 294;
	//	h
	m_nCharWidth[71].left = 454;
	m_nCharWidth[71].top = 196;
	m_nCharWidth[71].right = 496;
	m_nCharWidth[71].bottom = 294;
	//	i
	m_nCharWidth[72].left = 497;
	m_nCharWidth[72].top = 196;
	m_nCharWidth[72].right = 522;
	m_nCharWidth[72].bottom = 294;
	//	j
	m_nCharWidth[73].left = 522;
	m_nCharWidth[73].top = 196;
	m_nCharWidth[73].right = 568;
	m_nCharWidth[73].bottom = 294;
	//	k
	m_nCharWidth[74].left = 568;
	m_nCharWidth[74].top = 196;
	m_nCharWidth[74].right = 610;
	m_nCharWidth[74].bottom = 294;
	//	l
	m_nCharWidth[75].left = 610;
	m_nCharWidth[75].top = 196;
	m_nCharWidth[75].right = 630;
	m_nCharWidth[75].bottom = 294;
	//	m
	m_nCharWidth[76].left = 630;
	m_nCharWidth[76].top = 196;
	m_nCharWidth[76].right = 694;
	m_nCharWidth[76].bottom = 294;
	//	n
	m_nCharWidth[77].left = 694;
	m_nCharWidth[77].top = 196;
	m_nCharWidth[77].right = 736;
	m_nCharWidth[77].bottom = 294;
	//	o
	m_nCharWidth[78].left = 737;
	m_nCharWidth[78].top = 196;
	m_nCharWidth[78].right = 772;
	m_nCharWidth[78].bottom = 294;
	//	p
	m_nCharWidth[79].left = 773;
	m_nCharWidth[79].top = 196;
	m_nCharWidth[79].right = 814;
	m_nCharWidth[79].bottom = 294;
	//	q
	m_nCharWidth[80].left = 814;
	m_nCharWidth[80].top = 196;
	m_nCharWidth[80].right = 858;
	m_nCharWidth[80].bottom = 294;
	//	r
	m_nCharWidth[81].left = 858;
	m_nCharWidth[81].top = 196;
	m_nCharWidth[81].right = 899;
	m_nCharWidth[81].bottom = 294;
	//	s
	m_nCharWidth[82].left = 900;
	m_nCharWidth[82].top = 196;
	m_nCharWidth[82].right = 934;
	m_nCharWidth[82].bottom = 294;
	//	t
	m_nCharWidth[83].left = 935;
	m_nCharWidth[83].top = 196;
	m_nCharWidth[83].right = 978;
	m_nCharWidth[83].bottom = 294;
	//	u
	m_nCharWidth[84].left = 978;
	m_nCharWidth[84].top = 196;
	m_nCharWidth[84].right = 1020;
	m_nCharWidth[84].bottom = 294;
	//	v
	m_nCharWidth[85].left = 1020;
	m_nCharWidth[85].top = 196;
	m_nCharWidth[85].right = 1056;
	m_nCharWidth[85].bottom = 294;
	//	w
	m_nCharWidth[86].left = 1056;
	m_nCharWidth[86].top = 196;
	m_nCharWidth[86].right = 1114;
	m_nCharWidth[86].bottom = 294;
	//	x
	m_nCharWidth[87].left = 1114;
	m_nCharWidth[87].top = 196;
	m_nCharWidth[87].right = 1154;
	m_nCharWidth[87].bottom = 294;
	//	y
	m_nCharWidth[88].left = 1154;
	m_nCharWidth[88].top = 196;
	m_nCharWidth[88].right = 1196;
	m_nCharWidth[88].bottom = 294;
	//	z
	m_nCharWidth[89].left = 1196;
	m_nCharWidth[89].top = 196;
	m_nCharWidth[89].right = 1234;
	m_nCharWidth[89].bottom = 294;
	//	{
	m_nCharWidth[90].left = 0;
	m_nCharWidth[90].top = 292;
	m_nCharWidth[90].right = 32;
	m_nCharWidth[90].bottom = 382;
	//	|
	m_nCharWidth[91].left = 32;
	m_nCharWidth[91].top = 292;
	m_nCharWidth[91].right = 44;
	m_nCharWidth[91].bottom = 382;
	//	}
	m_nCharWidth[92].left = 44;
	m_nCharWidth[92].top = 292;
	m_nCharWidth[92].right = 80;
	m_nCharWidth[92].bottom = 382;
	//	~
	m_nCharWidth[93].left = 80;
	m_nCharWidth[93].top = 292;
	m_nCharWidth[93].right = 116;
	m_nCharWidth[93].bottom = 382;
				  



}
